/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// pbutton.hpp - Definition of all PegButton classes.
//
// Author: Kenneth G. Maxwell
//
// Copyright (c) 1997-2000 Swell Software
//              All Rights Reserved.
//
// Unauthorized redistribution of this source code, in whole or part,
// without the express written permission of Swell Software
// is strictly prohibited.
//
// Notes:
//
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef _PEGBUTTON_
#define _PEGBUTTON_


/*--------------------------------------------------------------------------*/
// The definitions below specify padding and separation used by the button
// types when constructed with only the top-left position specified, and
// also the separation between the checkbox and radio button indicators and
// the associated text. These values can be adjusted to preference.
/*--------------------------------------------------------------------------*/


#ifndef BBUTTON_PADDING
 #define BBUTTON_PADDING 3
#endif


#ifndef BUTTON_GRAD_SLICE
 #define BUTTON_GRAD_SLICE 16
#endif


/*--------------------------------------------------------------------------*/
// PegRadioButton Bitmap Indexes
/*--------------------------------------------------------------------------*/
enum PBMI_RADIO_BMPS {
    PBMI_RADIO_ON = 0,      // Selected
    PBMI_RADIO_OFF,         // Not Selected
    PBMI_RADIO_ON_DIS,      // Selected, disabled
    PBMI_RADIO_OFF_DIS,     // Not Selected, disabled
    PBMI_RADIO_ON_FOC,      // Selected, focused
    PBMI_RADIO_OFF_FOC      // Not Selected, focused
};

/*--------------------------------------------------------------------------*/
// PegCheckBox Bitmap Indexes
/*--------------------------------------------------------------------------*/
enum PBMI_CHECKBOX_BMPS {
    PBMI_CHECK_ON = 0,      // Checked
    PBMI_CHECK_OFF,         // Not Checked
    PBMI_CHECK_ON_DIS,      // Checked, disabled
    PBMI_CHECK_OFF_DIS,     // No Checked, disabled
    PBMI_CHECK_ON_FOC,      // Checked, focused
    PBMI_CHECK_OFF_FOC      // Not Checked, focused
};

/*--------------------------------------------------------------------------*/
// PegBitmapButton Bitmap Indexes
/*--------------------------------------------------------------------------*/
enum PBMI_BMBTN_BMPS {
    PBMI_NORMAL = 0,      // Default bitmap
    PBMI_PRESSED,         // Pressed bitmap
    PBMI_FOCUS,           // Has focus
    PBMI_DISABLED         // Disabled
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
#ifdef PEG_PRO
enum
{
    PCI_BTN_BORDER1 = 0,
    PCI_BTN_BORDER1_PSH,
    PCI_BTN_TEXT,      // KEEP NORMAL TEXT AND SELECTED TEXT
    PCI_BTN_TEXT_PSH,  // IN THEIR ORIGINAL POSITIONS FOR COMPATIBILITY
    PCI_BTN_TEXT_FOC,
    PCI_BTN_TEXT_DIS,
    PCI_BTN_BORDER1_FOC,
    PCI_BTN_BORDER1_DIS,
    PCI_BTN_BORDER2,
    PCI_BTN_BORDER2_PSH,
    PCI_BTN_BORDER2_FOC,
    PCI_BTN_BORDER2_DIS,
    PCI_BTN_GRAD1,
    PCI_BTN_GRAD1_PSH,
    PCI_BTN_GRAD1_FOC,
    PCI_BTN_GRAD1_DIS,
    PCI_BTN_GRAD2,
    PCI_BTN_GRAD2_PSH,
    PCI_BTN_GRAD2_FOC,
    PCI_BTN_GRAD2_DIS,
    MAX_EXT_BTN_COLORS
};
#endif

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegButton : public PegTextThing
{
    public:
        PegButton(void);

        PegButton(const PegRect &Size,  PEGUINT StringId = 0, PEGUSHORT Id = 0,
                #ifdef PEG_BTN_FLYOVER
                  PEGULONG Style = AF_ENABLED|FF_RAISED|BF_FLYOVER,
                #else
                  PEGULONG Style = AF_ENABLED|FF_RAISED,
                #endif
                  PEGUINT FontIndex = 0);

        PegButton(const PEGCHAR *pText, const PegRect &Size, PEGUSHORT Id = 0,
                #ifdef PEG_BTN_FLYOVER
                  PEGULONG Style = TT_COPY|AF_ENABLED|FF_RAISED|BF_FLYOVER,
                #else
                  PEGULONG Style = TT_COPY|AF_ENABLED|FF_RAISED,
                #endif
                  PEGUINT FontIndex = 0);

        virtual ~PegButton();

        void Disable(void);
        virtual void Draw(const PegRect &Invalid);
        virtual void DrawBorder(PEGUINT c1, PEGUINT c2);
        void Enable(void);

       #ifdef PEG_PRO
        virtual PEGUINT GetColor(const PEGUBYTE Index);
        virtual PEGULONG GetGradientStyle() { return mGrad.Style; }
       #endif

        virtual void HandleDownClick(PEGINT ButtonType);
        virtual void HandleUpClick(const PegMessage &Mesg);

        virtual void Initialize(PEGULONG Style);

        virtual PEGBOOL IsSelected(void)
        {
            if (mStyle & BF_PUSHED)
            {
                return TRUE;
            }
            return FALSE;
        }

        virtual PEGINT Message(const PegMessage &Mesg);

       #ifdef PEG_PRO
        virtual void Resize(const PegRect &Size);
        virtual void SetColor(const PEGUBYTE Index, const PEGUINT ColorId);
        virtual void SetGradientStyle(PEGULONG Style) { mGrad.Style = Style; }
       #endif

        virtual void SetSelected(PEGBOOL Selected = TRUE);
        virtual void SetStyle(PEGULONG Style);

    protected:
        void CheckSignal(PEGBOOL Selected);

        void UnselectSiblings(void) const;

       #ifdef PEG_PRO
        void UpdateGradColors();

        PEGUINT mExtColorIDs[MAX_EXT_BTN_COLORS];
        PegGradientStruct mGrad;
       #endif

        PEGBOOL mKeyPressed;

       #ifdef PEG_BTN_FLYOVER
        PEGBOOL mInFlyOver;
       #endif
};


/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegIconButton : public PegButton
{
    public:
        PegIconButton(const PegRect &Size, PEGUINT BmpId, PEGUSHORT Id = 0,
            PEGULONG Style = AF_ENABLED|FF_RAISED|BF_BMHCENTER|BF_BMVCENTER
           #ifdef PEG_BTN_FLYOVER
                | BF_FLYOVER
           #endif
            );

        virtual ~PegIconButton() {}

        virtual void Draw(const PegRect &Invalid);
        virtual PEGUINT GetBitmap(void) { return mBitmapId; }
        virtual void SetBitmap(PEGUINT BmpId) { mBitmapId = BmpId; }

    protected:

        PEGUINT mBitmapId;

};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegTextButton : public PegButton
{
    public:
        PegTextButton(const PegRect &Size, PEGUINT StringId = 0,
                      PEGUSHORT Id = 0,
                    #ifdef PEG_BTN_FLYOVER
                      PEGULONG Style = AF_ENABLED|FF_RAISED|BF_FLYOVER);
                    #else
                      PEGULONG Style = AF_ENABLED|FF_RAISED);
                    #endif

        PegTextButton(const PEGCHAR *pText, const PegRect &Size, 
                      PEGUSHORT Id = 0,
                    #ifdef PEG_BTN_FLYOVER
                      PEGULONG Style = TT_COPY|AF_ENABLED|FF_RAISED|BF_FLYOVER);
                    #else
                      PEGULONG Style = TT_COPY|AF_ENABLED|FF_RAISED);
                    #endif

        virtual ~PegTextButton() {}

        virtual void Draw(const PegRect &Invalid);
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegBitmapButton : public PegButton
{
    public:
        PegBitmapButton(const PegRect &Size, PEGUINT NormalBmp,
            PEGUINT PressedBmp, PEGUINT FocusedBmp = 0, PEGUSHORT Id = 0,
            PEGULONG Style = AF_ENABLED|FF_NONE|BF_BMHCENTER|BF_BMVCENTER
              #ifdef PEG_BTN_FLYOVER
                | BF_FLYOVER
              #endif
            );

        virtual void AssignBitmaps(PEGUINT NormalBmp, PEGUINT PressedBmp,
            PEGUINT FocusedBmp = 0, PEGUINT DisabledBmp = 0);
 
        virtual void Draw(const PegRect &Invalid);

        virtual PEGUINT GetBitmap(PEGUINT Index)
        {
            if (Index < 4)
            {
                return mBmpIds[Index];
            }

            return 0;
        }

        virtual PEGINT Message(const PegMessage &Mesg);

        virtual void SetBitmap(PEGUINT Index, PEGUINT BitmapId);

    protected:
        PEGUINT mBmpIds[4];

};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegRadioButton : public PegButton
{
    public:
        PegRadioButton(const PegRect &Size, PEGUINT StringId = 0,
            PEGUSHORT Id = 0,
          #ifdef PEG_BTN_FLYOVER
            PEGULONG Style = AF_ENABLED|FF_NONE|BF_EXCLUSIVE|BF_FLYOVER);
          #else
            PEGULONG Style = AF_ENABLED|FF_NONE|BF_EXCLUSIVE);
          #endif

        PegRadioButton(const PEGCHAR *pText, const PegRect &Size,
            PEGUSHORT Id = 0,
          #ifdef PEG_BTN_FLYOVER
            PEGULONG Style = TT_COPY|AF_ENABLED|FF_NONE|BF_EXCLUSIVE|BF_FLYOVER);
          #else
            PEGULONG Style = TT_COPY|AF_ENABLED|FF_NONE|BF_EXCLUSIVE);
          #endif
  
        virtual ~PegRadioButton() {}

        virtual void Draw(const PegRect &Invalid);

        virtual PEGUINT GetBitmap(PEGUINT Index)
        {
            if (Index < 4)
            {
                return mBmpIds[Index];
            }

            return 0;
        }

        virtual void SetBitmap(PEGUINT Index, PEGUINT BitmapId);
        virtual void SetSelected(PEGBOOL Selected = TRUE);


    protected:
        void RadioButtonInit(void);
        void UnselectSiblings(void) const;
        PEGUINT mBmpIds[6];
};

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
class PegCheckBox : public PegButton
{
    public:
        PegCheckBox(const PegRect &Size, PEGUINT StringId, PEGUSHORT Id = 0,
          #ifdef PEG_BTN_FLYOVER
            PEGULONG Style = AF_ENABLED|FF_NONE|BF_TOGGLE|BF_FLYOVER);
          #else
            PEGULONG Style = AF_ENABLED|FF_NONE|BF_TOGGLE);
          #endif

        PegCheckBox(const PEGCHAR *pText, const PegRect &Size, PEGUSHORT Id = 0,
          #ifdef PEG_BTN_FLYOVER
            PEGULONG Style = TT_COPY|AF_ENABLED|FF_NONE|BF_TOGGLE|BF_FLYOVER);
          #else
            PEGULONG Style = TT_COPY|AF_ENABLED|FF_NONE|BF_TOGGLE);
          #endif

        virtual ~PegCheckBox() {}

        virtual void Draw(const PegRect &Invalid);

        virtual PEGUINT GetBitmap(PEGUINT Index)
        {
            if (Index < 4)
            {
                return mBmpIds[Index];
            }

            return 0;
        }

        virtual PEGBOOL IsChecked(void)
        {
            if (mStyle & BF_PUSHED)
            {
                return TRUE;
            }
            return FALSE;
        }

        virtual void SetBitmap(PEGUINT Index, PEGUINT BitmapId);
        virtual void SetSelected(PEGBOOL Selected = TRUE);

    protected:
        void CheckBoxInit(void);
        PEGUINT mBmpIds[6];
};



#endif

